home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / logbatch / home.arc / HOME.ASM < prev    next >
Assembly Source File  |  1988-05-20  |  5KB  |  203 lines

  1.     page    61, 132
  2.     title    HOME - MAP a drive to user's SYS:MAIL directory
  3.     subttl    macros and data
  4.  
  5.  
  6. funct        macro    command
  7.         mov    ah, command
  8.         int    21h
  9.         endm
  10.  
  11. Print        macro    asciiz
  12.         push    si
  13.         lea    si, asciiz
  14.         call    print_asciiz
  15.         pop    si
  16.         endm
  17.     page    +
  18. ;***************************************************
  19. ;* Log Function 16: Get a Connection's Information *
  20. ;***************************************************
  21. E3h16h_request    struc
  22.         dw    2
  23.         db    16H
  24. Connection     db    ?
  25. E3h16h_request    ends
  26.  
  27. E3h16h_reply    struc
  28.         dw    62
  29. UniqueID    dd    ?
  30.         dw    ?
  31.         db    48 dup(?)
  32.         db    8 dup(?)
  33. E3h16h_reply    ends
  34.  
  35. ;****************************************************
  36. ;* Directory Function 18: Allocate a Permanent Base *
  37. ;****************************************************
  38. E2h12h_request    struc
  39. PacketLength    dw    ?
  40.         db    012h
  41.         db    0
  42. DriveName    db    ?
  43. SpecLength    db    ?
  44. PathSpec    db    'SYS:MAIL\'
  45. directory    db    8 dup(?)
  46. E2h12h_request    ends
  47.  
  48. E2h12h_reply    struc
  49.         dw    2
  50. NewBase        db    ?
  51. AccessMask    db    ?
  52. E2h12h_reply    ends
  53.     page    +
  54. Code    segment
  55.     assume    CS:Code, DS:Code, ES:nothing, SS:nothing
  56.     org    0100H
  57.  
  58. Begin:        jmp    Check_args
  59.         db    'v 1.00'
  60.         db    '(C)1988 Mark Halvin', 01AH
  61. hex_digits    db    '0123456789ABCDEF'
  62. BadArgs        db    'Usage:  HOME [drive:]', 07h, 0
  63. MapError    db    'Error mapping drive', 07h, 0
  64. leading_zero    db    0
  65.     even
  66. getID_req    E3h16h_request    <>
  67.     even
  68. getID_rep    E3h16h_reply    <>
  69.     even
  70. MAPbase_req    E2h12h_request    <>
  71.     even
  72. MAPbase_rep    E2h12h_reply    <>
  73.     subttl    subroutines
  74.     page    +
  75. print_asciiz    proc    near        ;print to StdOut the AsciiZ
  76.         push    ax        ; string pointed to by SI
  77.         push    dx
  78.         push    si
  79.         mov    ah, 2        ;MS-DOS Character Output
  80.  
  81.     l1:    mov    dl, [si]    ;get output character
  82.         cmp    dl, 0        ;is it a delimiter?
  83.         je    l2        ;yes -- done.
  84.         int    21h        ;call DOS to print character
  85.         inc    si        ;prepare for next character
  86.         jmp    l1
  87.  
  88.     l2:    pop    si
  89.         pop    dx
  90.         pop    ax
  91.         ret
  92. print_asciiz    endp
  93.  
  94. ax2hex        proc    near        ;convert number in AX to
  95.         mov    dx, ax        ; ascii hex digits, stored
  96.         mov    cl, 12        ;  at DI. length returned in BL.
  97.         shr    ax, cl
  98.         call    al2hex
  99.         mov    ax, dx
  100.         mov    cl, 8
  101.         shr    ax, cl
  102.         and    ax, 000Fh
  103.         call    al2hex
  104.         mov    ax, dx
  105.         mov    cl, 4
  106.         shr    al, cl
  107.         and    ax, 000Fh
  108.         call    al2hex
  109.         mov    ax, dx
  110.         and    ax, 000Fh
  111.         call    al2hex
  112.         ret
  113. ax2hex        endp
  114.  
  115. al2hex        proc    near        ;converts one hex character in AL
  116.         mov    si, ax
  117.         mov    al, byte ptr[hex_digits + si]    ;convert character
  118.         cmp    leading_zero, 0        ;has a digit been printed?
  119.         jne    l3            ; yes.
  120.         cmp    al, '0'            ;no, is this a zero?
  121.         je    l4            ; yes, don't print it.
  122.         mov    leading_zero, 0FFh    ;no, set flag for next time.
  123.     l3:    mov    [di], al        ;place output
  124.         inc    bl
  125.         inc    di
  126.     l4:    ret
  127. al2hex        endp
  128.     subttl    argument checking code
  129.     page    +
  130. home        proc    near
  131. Check_args:    mov    si, 81h        ;initial offset to parameters
  132.     scan:    mov    al, [si]    ;get character
  133.         cmp    al, 0Dh        ;is it a CR?
  134.         je    default        ; yep -- no parameters, use default
  135.         cmp    al, ' '        ;is it a space?
  136.         je    again        ; yep -- keep scanning
  137.         and    al, 11011111b    ;no, force it to upper case
  138.         cmp    al, 'A'
  139.         jb    arg_err        ;too low (below A)
  140.         cmp    al, 'Z'
  141.         ja    arg_err        ;too high (above Z)
  142.         mov    MAPbase_req.DriveName, al    ;save drive to map
  143.         jmp    check_rest
  144.     again:    inc    si
  145.         jmp    scan
  146.  
  147. check_rest:    inc    si            ;make sure drive letter
  148.         cmp    byte ptr[si], ':'    ; has a colon after it.
  149.         jne    arg_err
  150.         jmp    Start
  151.  
  152. default:    funct    19h            ;Get Current Disk.
  153.         add    al, 'A'            ;convert it to ASCII
  154.         mov    MAPbase_req.DriveName, al    ;save it for later
  155.     subttl    program code
  156.     page    +
  157. Start:        funct    0DCh            ;Get Station Number.
  158.         mov    getID_req.Connection, al    ; and save it
  159.  
  160.         lea    si, getID_req
  161.         lea    di, getID_rep
  162.         funct    0E3h        ;Get a Connection's Information.
  163.  
  164.         ;*******************************************
  165.         ;* Translate binary UniqueID to ASCII hex. *
  166.         ;* Keep length of ASCII ID string in BL.   *
  167.         ;*******************************************
  168.         lea    di, MAPbase_req.directory    ;destination of ID
  169.         xor    bl, bl                ;size of string
  170.  
  171.         mov    ax, word ptr[getID_rep.UniqueID]
  172.         xchg    al, ah
  173.         call    ax2hex        ;convert AX to ASCII hex at DI
  174.         mov    ax, word ptr[getID_rep.UniqueID + 2]
  175.         xchg    al, ah
  176.         call    ax2hex        ;convert AX to ASCII hex at DI
  177.  
  178.         add    bl, 9        ;add ID string length to 'SYS:MAIL\'
  179.         mov    MAPbase_req.SpecLength, bl    ; and store it
  180.         add    bl, 4        ;add up total reply packet length
  181.         xor    bh, bh        ;clear high byte
  182.         mov    MAPbase_req.PacketLength, bx    ; and store it
  183.  
  184.         lea    si, MAPbase_req
  185.         lea    di, MAPbase_rep
  186.         funct    0E2h        ;Allocate a Permanent Base.
  187.         jnc    NoError
  188.         Print    MapError    ;error mapping base
  189.         mov    al, 3        ;return ERRORLEVEL 3
  190.         jmp    Terminate
  191.  
  192. arg_err:    Print    BadArgs        ;argument error
  193.         mov    al, 1        ;abort with ERRORLEVEL 1
  194.         jmp    Terminate
  195.  
  196. NoError:    xor    al, al        ;no ERRORLEVEL
  197.  
  198. Terminate:    funct    4Ch        ;Terminate Process.
  199. home        endp
  200.  
  201. Code    ends
  202.     end    Begin
  203.